package dk.hewison.client.component;

import com.google.gwt.user.client.ui.*;

/**
 * @author John Hewison
 * @author $LastChangedBy: john.hewison $:  $ $LastChangedDate: 2009-02-01 11:43:30 +0000 (Sun, 01 Feb 2009) $:
 * @version $Revision: 32 $:
 */
public class LogDlg extends DialogBox {
    private VerticalPanel listBox = new VerticalPanel();
    private ScrollPanel scrollPanel;

    public LogDlg() {
        super(false, false);
        super.setText("Log");

        addStyleName("log");
        //setStyleName("log");

        Button closeButton = new Button("Close", new ClickListener() {
            public void onClick(Widget sender) {
                hide();
            }
        });

        scrollPanel = new ScrollPanel(listBox);
        scrollPanel.setPixelSize(500, 400);

        DockPanel dockPanel = new DockPanel();
        dockPanel.add(scrollPanel, DockPanel.CENTER);
        dockPanel.add(closeButton, DockPanel.SOUTH);

        add(dockPanel);


    }

    public void setLogText(StringBuffer log) {
        listBox.clear();
        String[] logArrayList = log.toString().split("\n");

        for (String s : logArrayList) {
            listBox.add(new Label(s));
        }
        scrollPanel.setScrollPosition(10000000);
    }

    public void appendMessage(String logEntry) {
        listBox.add(new Label(logEntry));
        scrollPanel.setScrollPosition(10000000);
    }
}
